var vmOne = new Vue({
  el: '#app',
  data:{
      replydata:"",
      strname:"",
      pageDataCurrent: []
  }
});

var socket;
function Connect(){
    try{
        socket = new WebSocket('ws://192.168.100.157:9000/phone');
    }catch(e){
        return;
    }
    socket.onopen = sOpen;
    socket.onerror = sError;
    socket.onmessage = sMessage;
    socket.onclose = sClose;
}
function sOpen(){
    var msgbody = '服务器连接成功';
    console.log(msgbody);
}
function sError(){
    var msgbody = '服务器异常Error=' + e + '请检查';
    console.log(msgbody);
}
function sMessage(msg){
}
function sClose(e){
    var msgbody = '服务器连接关闭ErrorCode=' + e.code;
    console.log(msgbody);
}
function sSend(msg){
    var data = vmOne.strname + ":" + msg;
    console.log("------------" + data);
    socket.send(data);
}

Connect();

var game = new Game()
game.init()
game.addSuccessFn(success)
game.addFailedFn(failed)

var mask = document.querySelector('.mask')
var restartButton = document.querySelector('.restart')
var score = document.querySelector('.score')

restartButton.addEventListener('click', restart)

// 游戏重新开始，执行函数
function restart() {
  mask.style.display = 'none'
  game.restart()
}
// 游戏失败执行函数
function failed() {
  score.innerText = game.score
  mask.style.display = 'flex'
}
// 游戏成功，更新分数
function success(score) {
  console.log("hello world" + score);
  sSend(score);
  var scoreCurrent = document.querySelector('.score-current');
  scoreCurrent.innerText = score;
}
